package com.heba.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

import com.heba.greenmulu.R;

import java.util.List;

/**
 * Created by jason on 2019/4/2.
 */
public class YearMonthSelectDialog {

    private OnDialogClickListener dialogClickListener;

    public YearMonthSelectDialog(OnDialogClickListener dialogClickListener) {
        this.dialogClickListener = dialogClickListener;
    }

    /**
     * 获取年份对话框列表
     *
     * @param context
     * @param years
     */
    public void getYearsDialog(Context context, List<String> years) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(context.getResources().getString(R.string.year_select));
        builder.setItems(years.toArray(new String[years.size()]), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (dialogClickListener != null) {
                    dialogClickListener.onItemClick(years.get(which));
                }
            }
        });
        builder.show();
    }

    /**
     * 获取月份对话框列表
     *
     * @param context
     * @param months
     */
    public void getMonthDialoh(Context context, String[] months) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(context.getResources().getString(R.string.month_select));
        builder.setItems(months, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (dialogClickListener != null) {
                    dialogClickListener.onItemMonthClick(months[which], which);
                }
            }
        });
        builder.show();
    }

    /**
     * 回调接口
     */
    public interface OnDialogClickListener {

        void onItemClick(String content);

        void onItemMonthClick(String content, int position);

    }

}
